define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'goods.shelves/index',
        add_url: 'goods.shelves/add',
        edit_url: 'goods.shelves/edit',
        delete_url: 'goods.shelves/delete',
        export_url: 'goods.shelves/export',
        modify_url: 'goods.shelves/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '商品ID'},
                    {field: 'img', title: '商品图片',templet: ea.table.image},
                    {field: 'code', title: '商品编码'},
                    {field: 'name', title: '商品名称'},
                    {field: 'category_name', title: '商品类别'},
                    {field: 'view_price', title: '价格'},
                    {field: 'summary', title: '商品短描述'},
                    {field: 'count', title: '数量'},
                    {field: 'state', title: '商品状态',
                    templet: function(d){
                        if(d.state == 0){return "未上架"}
                        if(d.state == 1){return "上架"}
                        if(d.state == 2){return "已下架"}
                        if(d.state == -1){return "已删除"}
                    }
                    },
                    {width: 250, title: '操作', templet: ea.table.tool},
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});